class User < ActiveRecord::Base		
	has_many :questions, :foreign_key => 'student_id'
	has_and_belongs_to_many :grades
	has_and_belongs_to_many :subjects
	has_many :qa_details
	has_many :ratings
	
	include GlobalContants
	named_scope :teachers, lambda {
		{:conditions => {:role => USER_ROLE_STATUS[:teacher]}}
	}

	named_scope :students, lambda {
		{:conditions => {:role => USER_ROLE_STATUS[:student]}}
	}

	def self.authenticate(user_name,password)
		user = User.first(:conditions => {
			:user_name => user_name,
			:password => password
		})

		!user.blank?
	end
end
